﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MKS.BLL;
using MKS.model;

namespace MarketMS
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_KeyUp(object sender, KeyEventArgs e)
        {
            if(e.KeyCode==Keys.F2){
                txtqw.Focus();
            }
        }
        
        private List<BuyGoodsInfo> ga = new List<BuyGoodsInfo>();
        private Helper st = new Helper();
        private void butsuo_Click(object sender, EventArgs e)
        {
            if (txtqw.Text != "")
            {
                List<GoodsInfo> list = st.GetCode(txtqw.Text);
                BuyGoodsInfo wan = new BuyGoodsInfo();
                if (list.Count == 0)
                {
                    MessageBox.Show("没有商品");
                }
                else if (list.Count == 1)
                {
                    wan.GoodsName = list[0].GoodsName;
                    wan.SalePrice = list[0].SalePrice;
                    wan.Buy = 1;
                    ga.Add(wan);
                }
                else
                {
                    BuyGoods wa = new BuyGoods(list);
                   
                    wa.ShowDialog();
                    GoodsInfo g = wa.SelectedGood; 

                   wan.GoodsName = g.GoodsName;
                   wan.SalePrice = g.SalePrice;
                   wan.Buy = 1;
                   ga.Add(wan);
                }
                
                dgvshaoping.DataSource = new BindingList<BuyGoodsInfo>(ga);
                txtqw.Text = "";
            }
        }

        private void txtqw_KeyUp(object sender, KeyEventArgs e)
        {
            if(e.KeyCode==Keys.Enter ){
                if (txtqw.Text != "")
                {
                    butsuo_Click(null,null);
                }
            }
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            dgvshaoping.AutoGenerateColumns = false;
           
        }

    }
}
